package dayplay;

import java.util.Arrays;
import java.util.Random;

public class Pokers {
    public static void main (String[] args) {
        //创建一副扑克牌
        String[] pokers = pokers();

        //洗牌(无规则打乱顺序)
        String[] shuffle = shuffle(pokers);


        //发牌
        deal(shuffle);
    }

    private static void deal (String[] shuffle) {
        String player1[] = new String[shuffle.length / 3];
        String player2[] = new String[shuffle.length / 3];
        String player3[] = new String[shuffle.length / 3];

        int p1 = 0;
        int p2 = 0;
        int p3 = 0;

        for (int i = 0; i < shuffle.length; i++) {
            if (i % 3 == 0) {
                player1[p1] = shuffle[i];
                p1++;
            }
            if (i % 3 == 1) {
                player2[p2] = shuffle[i];
                p2++;
            }
            if (i % 3 == 2) {
                player3[p3] = shuffle[i];
                p3++;
            }
        }

        System.out.println("玩家1" + Arrays.toString(player1));
        System.out.println("玩家2" + Arrays.toString(player2));
        System.out.println("玩家3" + Arrays.toString(player3));
    }

    private static String[] shuffle (String[] pokers) {
        boolean pokerSwitch[] = new boolean[pokers.length];
        String[] newpokers = new String[pokers.length];

        Random rd = new Random();
        int a = 0;
        int b = 0;
        while (true) {
            int i = rd.nextInt(pokers.length);
            if (pokerSwitch[i] == false) {
                newpokers[a] = pokers[i];
                a++;
                b++;
                pokerSwitch[i] = true;
            }
            if (b == 54) {
                break;
            }

        }
        System.out.println("洗过牌:" + Arrays.toString(newpokers));
        return newpokers;

    }

    private static String[] pokers () {
        String pokers[] = new String[54];
        int number[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13};
        String suit[] = {"红桃", "方片", "梅花", "黑桃"};

        int index = 0;
        for (int i = 0; i < suit.length; i++) {
            for (int j = 0; j < number.length; j++) {
                pokers[index] = suit[i] + number[j];
                index++;
            }
        }
        pokers[52] = "大王";
        pokers[53] = "小王";
        System.out.println("新建牌:" + Arrays.toString(pokers));
        return pokers;
    }
}
/*
 * 1.创建一副扑克牌,要求花色+数字;1-13  红桃,方片,黑桃,梅花(Tips:可以使用嵌套for循环)---输出至控制台
 *2.无规则打乱顺序,---输出至控制台
 * 3,将打乱顺序的牌 按照ABC ABC ABC的顺序发给 三个玩家  不需要保留底牌---输出至控制台(三个玩家)
 *
 * */
